package Demo05172;

import java.util.Set;

public class TestSet {
    public void addEmp(Set<Emp> set, Emp emp) {
        set.add(emp);
    }

    public void findAllEmp(Set<Emp> set) {
        for (Emp emp : set) {
            System.out.println(emp);
        }
    }

    public Emp findEmpName(Set<Emp> set, String name) {
        for (Emp emp : set) {
            if (name.equals(emp.getName())) {
                return emp;
            }
        }
        return null;
    }

    public void deleteEmpNumber(Set<Emp> set, String number) {
        set.removeIf(emp -> number.equals(emp.getNumber()));
        System.out.println(set);
    }

    public Emp findEmpNumber(Set<Emp> set, String number) {
        for (Emp emp : set) {
            if (number.equals(emp.getNumber())) {
                return emp;
            }
        }
        return null;
    }

    public void updateEmpAge(Set<Emp> set, Emp emp) {
        // First remove the existing employee if present
        set.removeIf(e -> emp.getNumber().equals(e.getNumber()));
        // Then add the updated employee
        set.add(emp);
        System.out.println(set);
    }
}